home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / mgr.zoo / mgrdif1.zoo / src / fast_scroll.c next >
Encoding:
C/C++ Source or Header  |  1991-03-01  |  6.9 KB  |  237 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: fast_scroll.c,v 1.1 89/03/17 08:21:06 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/fast_scroll.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/fast_scroll.c,v $$Revision: 1.1 $";
  12.  
  13. /*
  14.  * fast scroll for 68010 assuming byte boundaries  (SAU)
  15.  *    This code is highly machine dependent
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include "bitmap.h"
  20.  
  21. #define BYTESWIDE(x)    ((x->primary->wide+7)>>3)
  22.  
  23. #ifndef atarist        /* see below for atarist codeing */
  24. #ifndef mc68020
  25.  
  26. /* these macros rely upon the proper register assignments */
  27.  
  28. #define START(x)    asm("x:    movl    d7,d0")
  29. #define LOOP(l)        asm("l:    movw    a3@+,a4@+"); \
  30.             asm("    dbf    d0,l")
  31. #define GOTO(x)        asm("    dbf    d5,x")
  32. #define SKIP()        asm("    addl    d6,a4"); \
  33.             asm("    addl    d6,a3")
  34. #define BYTE()        asm("    movb    a3@+,a4@+")
  35. #define ADJ(x)        asm("    subql    #x,d7")
  36.  
  37. fast_scroll(map,x,y,wide,high,delta)
  38. register BITMAP *map;                    /* a5 */
  39. int x,y,wide,high,delta;
  40.    {
  41.    register unsigned char *dst = (unsigned char *)     /* a4 */
  42.          ((long) (map->data) + (y*BYTESWIDE(map) + (x>>3)));
  43.    register unsigned char *src =            /* a3 */
  44.          dst + (delta*BYTESWIDE(map));
  45.    register long count =                /* d7 */
  46.          (wide>>4) - 1;            /* # of shorts - 1 for inner dbf */
  47.    register long skip =                 /* d6 */
  48.          BYTESWIDE(map)-(wide>>3);    /* bytes to skip at right edge */
  49.    register long h =                     /* d5 */
  50.          high-delta-1;            /* # of lines to scroll */
  51.    int which = (((long) dst)&1) + ((skip&1)<<1);
  52.  
  53.    switch (which) {
  54.       case 0:            /* skip&1 == 0 */
  55.      START(C0); LOOP(LP0); SKIP(); GOTO(C0);
  56.          break;
  57.       case 1:
  58.          ADJ(1); START(C1); BYTE(); LOOP(LP1); BYTE(); SKIP(); GOTO(C1);
  59.          break;
  60.  
  61.       case 2:            /* skip&1 == 1 */
  62.      START(C2); LOOP(LP2); BYTE(); SKIP(); GOTO(C2);
  63.          break;
  64.       case 3:
  65.      START(C3); BYTE(); LOOP(LP3); SKIP(); GOTO(C3);
  66.          break;
  67.       }
  68.    }
  69.  
  70. /*
  71.  * fast scroll for 68020 assuming byte boundaries  (SAU)
  72.  *    This code is highly machine dependent
  73.  */
  74.  
  75. #else
  76.  
  77. /* these macros rely upon the proper register assignments */
  78.  
  79. #define START(x)    asm("x:    movl    d7,d0")
  80. #define LOOP(l)        asm("l:    movl    a3@+,a4@+"); \
  81.             asm("    dbf    d0,l")
  82. #define GOTO(x)        asm("    dbf    d5,x")
  83. #define SKIP()        asm("    addl    d6,a4"); \
  84.             asm("    addl    d6,a3")
  85. #define WORD()        asm("    movw    a3@+,a4@+")
  86. #define BYTE()        asm("    movb    a3@+,a4@+")
  87. #define ADJ(x)        asm("    subql    #x,d7")
  88.  
  89. fast_scroll(map,x,y,wide,high,delta)
  90. register BITMAP *map;                    /* a5 */
  91. int x,y,wide,high,delta;
  92.    {
  93.    register unsigned char *dst = (unsigned char *)     /* a4 */
  94.          ((long) (map->data) + (y*BYTESWIDE(map) + (x>>3)));
  95.    register unsigned char *src =            /* a3 */
  96.          dst + (delta*BYTESWIDE(map));
  97.    register long count =                /* d7 */
  98.          (wide>>5) - 1;            /* # of longs - 1 for inner dbf */
  99.    register long skip =                 /* d6 */
  100.          BYTESWIDE(map)-(wide>>3);    /* bytes to skip at right edge */
  101.    register long h =                     /* d5 */
  102.          high-delta-1;            /* # of lines to scroll */
  103.    int which = (((long) dst)&3) + ((skip&3)<<2);
  104.  
  105.    switch (which) {
  106.       case 0:            /* skip&3 == 0 */
  107.      START(C0); LOOP(LP0); SKIP(); GOTO(C0);
  108.          break;
  109.       case 1:
  110.          ADJ(1); START(C1); BYTE(); WORD(); LOOP(LP1); BYTE(); SKIP(); GOTO(C1);
  111.          break;
  112.       case 2:
  113.          ADJ(1); START(C2); WORD(); LOOP(LP2); WORD(); SKIP(); GOTO(C2);
  114.          break;
  115.       case 3:
  116.          ADJ(1); START(C3); BYTE(); LOOP(LP3); WORD(); BYTE(); SKIP(); GOTO(C3);
  117.          break;
  118.  
  119.       case 4:            /* skip&3 == 1 */
  120.      START(C4); LOOP(LP4); WORD(); BYTE(); SKIP(); GOTO(C4);
  121.          break;
  122.       case 5:
  123.      START(C5); BYTE(); WORD(); LOOP(LP5); SKIP(); GOTO(C5);
  124.          break;
  125.       case 6:
  126.      START(C6); WORD(); LOOP(LP6); BYTE(); SKIP(); GOTO(C6);
  127.          break;
  128.       case 7:
  129.      START(C7); BYTE(); LOOP(LP7); WORD(); SKIP(); GOTO(C7);
  130.          break;
  131.  
  132.       case 8:            /* count%4 == 2 */
  133.      START(C8); LOOP(LP8); WORD(); SKIP(); GOTO(C8);
  134.          break;
  135.       case 9:
  136.          ADJ(1); START(C9); BYTE(); WORD(); LOOP(LP9);
  137.          WORD(); BYTE(); SKIP(); GOTO(C9);
  138.          break;
  139.       case 10:
  140.      START(C10); WORD(); LOOP(LP10); SKIP(); GOTO(C10);
  141.          break;
  142.       case 11:
  143.      START(C11); BYTE(); LOOP(LP11); BYTE(); SKIP(); GOTO(C11);
  144.          break;
  145.  
  146.       case 12:            /* count%4 == 3 */
  147.      START(C12); LOOP(LP12); BYTE(); SKIP(); GOTO(C12);
  148.          break;
  149.       case 13:
  150.          ADJ(1); START(C13); BYTE(); WORD(); LOOP(LP13);
  151.          WORD(); SKIP(); GOTO(C13);
  152.          break;
  153.       case 14:
  154.          ADJ(1); START(C14); WORD(); LOOP(LP14); WORD();
  155.          BYTE(); SKIP(); GOTO(C14);
  156.          break;
  157.       case 15:
  158.      START(C15); BYTE(); LOOP(LP15); SKIP(); GOTO(C15);
  159.          break;
  160.       }
  161.    }
  162. #endif /* sun & mc68020 */
  163.  
  164. #else /* !atarist */
  165.  
  166.     /* ATARIST version -- assumes gcc */
  167.  
  168. #define START()    \
  169.   __asm__ volatile("1:    movl    %1,%0"         : "=d"(temp) : "d"(count))
  170.  
  171. #define LOOP() \
  172.   __asm__ volatile("2:    movw    %1@+,%0@+"  : "=a"(dst)  : "a"(src)); \
  173.   __asm__ volatile("    dbf    %0,2b"         : "=d"(temp))
  174.  
  175. #define GOTO() \
  176.   __asm__ volatile("    dbf    %0,1b"         : "=d"(h))
  177.  
  178. #define SKIP() \
  179.   __asm__ volatile("    addl    %1,%0"         : "=a"(dst) : "d"(skip)); \
  180.   __asm__ volatile("    addl    %1,%0"        : "=a"(src) : "d"(skip))
  181.  
  182. #define BYTE() \
  183.   __asm__ volatile("    movb    %1@+,%0@+"  : "=a"(dst)  : "a"(src))
  184.  
  185. #define ADJ(x) \
  186.   __asm__ volatile("    subql    %1,%0"      : "=d"(count) : "I"(x))
  187.  
  188. fast_scroll(map,x,y,wide,high,delta)
  189. BITMAP *map;            /* a5 */
  190. int x,y,wide,high,delta;
  191.    {
  192.    unsigned char *dst = (unsigned char *) /* a4 */
  193.          ((long) (map->data) + (y*BYTESWIDE(map) + (x>>3)));
  194.    unsigned char *src =            /* a3 */
  195.          dst + (delta*BYTESWIDE(map));
  196.    long count =                /* d7 */
  197.          (wide>>4) - 1;            /* # of shorts - 1 for inner dbf */
  198.    long skip =                 /* d6 */
  199.          BYTESWIDE(map)-(wide>>3);    /* bytes to skip at right edge */
  200.    long h =                 /* d5 */
  201.          high-delta-1;            /* # of lines to scroll */
  202.    long temp;                /* d0 */
  203.    int which = (((long) dst)&1) + ((skip&1)<<1);
  204.  
  205.    switch (which) {
  206.       case 0:            /* skip&1 == 0 */
  207.      START(); LOOP(); SKIP(); GOTO();
  208.          break;
  209.       case 1:
  210.          ADJ(1); START(); BYTE(); LOOP(); BYTE(); SKIP(); GOTO();
  211.          break;
  212.  
  213.       case 2:            /* skip&1 == 1 */
  214.      START(); LOOP(); BYTE(); SKIP(); GOTO();
  215.          break;
  216.       case 3:
  217.      START(); BYTE(); LOOP(); SKIP(); GOTO();
  218.          break;
  219.       }
  220.    }
  221.  
  222. #endif /* atarist */
  223.  
  224.  
  225.  
  226. #if 0
  227. /* normal bit-blit version of the above (for testing) */
  228.  
  229. Fast_scroll(map,x,y,wide,high,delta)
  230. register BITMAP *map;                    /* a5 */
  231. int x,y,wide,high,delta;
  232.    {
  233.    bit_blit(map,x&7,y,wide&7,high,
  234.             BIT_SRC,map,x&7,delta);
  235.    }
  236. #endif
  237.